#include <stdlib.h>
#include <string.h>



char NAMESPACE[64];
struct st_property{
	char *name; 
	char *type; 
};

struct st_property_ls {
 	struct st_property *property;
	struct st_property_ls *next;
};

struct st_model{
	char *name;
	struct st_property_ls *properties;
};

struct st_model_ls{
	struct st_model *model;	
	struct st_model_ls *next;	
};

int init_model_ls();
int add_model(char *name);
int add_property(char *name, char *type);
int properties_preview(struct st_property_ls *properties);
int model_preview(struct st_model *model);
int model_list_preview ();
int is_primitive_type(struct st_property *property);

struct st_model_ls *model_list;


int is_numeric_type(struct st_property *property){
	int i;
	for(i=0;NUMERICAL_TYPES[i]!=NULL;i++)
		if(strcmp(property->type,NUMERICAL_TYPES[i])==0)
			return VERDADERO;
	return FALSO;
}
int is_primitive_type(struct st_property *property){
	int i;
	for(i=0;PRIMITIVES[i]!=NULL;i++)
		if(strcmp(property->type,PRIMITIVES[i])==0)
			return VERDADERO;
	return FALSO;
}
int init_model_ls()
{
	free(model_list);
	model_list = NULL;
	return OK;
}

int add_model(char *name)
{
	struct st_model *model;
	struct st_model_ls *list;
	
	model = (struct st_model *)  malloc(sizeof(struct st_model ));
	model->name=(char *) malloc(sizeof(name));
	strcpy(model->name,name);
	model->properties = NULL;
	
	list = (struct st_model_ls *) malloc(sizeof(struct st_model_ls ));
	list->model = model;
	list->next = model_list;
	model_list = list;
	
	return OK;
}

int add_property(char *name, char *type)
{
	struct st_property *property;
	
	property = (struct st_property *) malloc(sizeof(struct st_property));
	
	property->name=(char *) malloc(sizeof(name));
	strcpy(property->name,name);
	
	
	property->type=(char *) malloc(sizeof(type));
	strcpy(property->type,type);
	
	if(model_list->model->properties==NULL)
	{
		model_list->model->properties = (struct st_property_ls *) malloc(sizeof(struct st_property_ls));
		model_list->model->properties->property = property;
		model_list->model->properties->next = NULL;		
	}
	else
	{
		struct st_property_ls  *next = (struct st_property_ls *) malloc(sizeof(struct st_property_ls));
		struct st_property_ls  *current = model_list->model->properties;
		
		
		next->property = property;
		next->next = NULL;
		
		
		while(current->next!=NULL)current=current->next;
		
		current->next = next;
	}
	
	return OK;	
}

int properties_preview(struct st_property_ls *properties)
{
	while(properties!=NULL)
	{
		if(properties->property!=NULL)
			printf("\t\t Property %s %s\n",properties->property->type,properties->property->name);
		else
			printf("\t\tPropiedad Invalida\n");
		properties = properties->next; 
	}
	return OK;
}

int model_preview(struct st_model *model)
{
	if(model==NULL)
		printf("\tModelo Invalido\n");
	printf("\tModelo: %s\n",model->name);	
	properties_preview(model->properties);
	return OK;
	
}

int model_list_preview ()
{
	struct st_model_ls *list =model_list;
	printf("Begin List\n");
	while(list!=NULL)
	{
		model_preview(list->model);
		list=list->next;
		
	}
	printf("End Preview\n");
	return OK;
}










